var express = require("express");
var router = express.Router();
var { Select } = require("../module/AdminModel");
var { BuildToken } = require("../utils/token");
/* GET home page. */
router.post("/", async function (req, res, next) {
  let result = await Select(req.body);
  if (result === undefined ||result ===null ) {
    res.send({ code: -1, msg: "登录失败，请重新检查账号和密码" });
  } else {
    let { username, password } = result;
    let token = BuildToken({ username, password });
    res.send({ code: 0, msg: "登录成功", token: token });
  }
});

module.exports = router;
